<?php $default_category = isset($id_category) ? get_parent_category_id($id_category) : 1; ?>
<script type="text/javascript">
    dojo.addOnLoad(function() {
        var idParentStore = new dojo.data.ItemFileReadStore({
            url:"<?php echo base_url() ?>admin/categories/json_combo"
        });
        var catParentSelect = new dijit.form.FilteringSelect({
            id:"category_parent",
            name:"parent",
            value:"<?php echo $default_category ?>",
            store:idParentStore,
            searchAttr: "name"
        },"category_parent");
    });
    
</script>
<script>
    dojo.addOnLoad(function(){
        var new_category = dijit.byId("new_category");
        dojo.connect(new_category, "onSubmit", function(e) {
            e.preventDefault();
            if (new_category.validate()) {
                var id_category = dojo.byId("id_category").value;
                var vi_cat_name = dojo.byId('vi_cat_name').value;
                var fr_cat_name = dijit.byId('fr_cat_name').value;
                var id_parent = dijit.byId("category_parent").get('value');
                var vi_description = dijit.byId("vi_description").value;
                var fr_description = dijit.byId("fr_description").value;
                var vi_link_rewrite = dijit.byId("vi_link_rewrite").value;
                var fr_link_rewrite = dijit.byId("fr_link_rewrite").value;
                var vi_meta_title = dijit.byId("vi_meta_title").value;
                var fr_meta_title = dijit.byId("fr_meta_title").value;
                var vi_meta_description = dijit.byId("vi_meta_description").value;
                var fr_meta_description = dijit.byId("fr_meta_description").value;
                var vi_meta_keywords = dijit.byId("vi_meta_keywords").value;
                var fr_meta_keywords = dijit.byId("fr_meta_keywords").value;
                
                var xhrArgs = {
                    url:"<?php echo site_url() . 'admin/categories/ajax_update_category'; ?>",
                    content:{
                        'id_category':id_category,
                        'vi_cat_name':vi_cat_name,
                        'fr_cat_name':fr_cat_name,
                        'id_parent':id_parent,
                        'vi_description':vi_description,
                        'fr_description':fr_description,
                        'vi_link_rewrite':vi_link_rewrite,
                        'fr_link_rewrite':fr_link_rewrite,
                        'vi_meta_title':vi_meta_title,
                        'fr_meta_title':fr_meta_title,
                        'vi_meta_description':vi_meta_description,
                        'fr_meta_description':fr_meta_description,
                        'vi_meta_keywords':vi_meta_keywords,
                        'fr_meta_keywords':fr_meta_keywords
                        
                    },
                    //postData:[dojo.toJson(new_category.attr("value")),
                    load:function(data){
                        window.location.href = "<?php echo site_url() . 'admin/categories/listing'; ?>";
                    },
                    error:function(error){
                        alert(error);
                    }
                }
                dojo.xhrPost(xhrArgs);
            }
        });
    });
</script>
<div dojoType="dijit.form.Form" id="new_category" jsId="new_category" encType="multipart/form-data" action="<?php echo current_url(); ?>" method="POST">
    <input type="hidden" id="id_category" name="id_category" value="<?php echo $id_category ?>" />
    <table width="99%" cellspacing="10" class="myForm">
        <tr>
            <td width="160">Tên danh mục Tiếng Việt:</td>
            <td>
                <div style="width:400px;" id="vi_cat_name" name="vi_cat_name" value="<?php echo $vi_category->name ?>" required="true" dojoType="dijit.form.ValidationTextBox"></div>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Tên danh mục Tiếng Pháp:</td>
            <td>
                <div style="width:400px;" id="fr_cat_name" name="fr_cat_name" value="<?php echo $fr_category->name ?>" required="true" dojoType="dijit.form.ValidationTextBox"></div>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Danh mục cha:</td>
            <td>
                <input id="category_parent">
            </td>
        </tr>
        <tr>
            <td width="150">Mô tả tiếng Việt:</td>
            <td>
                <div style="width: 400px;">
                    <div data-dojo-type="dijit.Editor" id="vi_description" data-dojo-props='height:"4",value:"<?php echo $vi_category->description ?>",extraPlugins:["tabIndent"]'>

                    </div>  
                </div>                                                      
            </td>
        </tr>
        <tr>
            <td width="150">Mô tả tiếng Pháp:</td>
            <td>
                <div style="width: 400px;">
                    <div data-dojo-type="dijit.Editor" id="fr_description" data-dojo-props='height:"4",value:"<?php echo $fr_category->description ?>",extraPlugins:["tabIndent"]'>

                    </div>  
                </div>                                                      
            </td>
        </tr>
        <tr>
            <td width="150">Link rewrite tiếng Việt :</td>
            <td>
                <div style="width:400px;" dojoType=dijit.form.TextBox name="vi_link_rewrite" id="vi_link_rewrite" value="<?php echo $vi_category->link_rewrite ?>">

                </div>
            </td>
        </tr>
        <tr>
            <td width="150">Link rewrite tiếng Pháp:</td>
            <td>
                <div style="width:400px;" dojoType=dijit.form.TextBox name="fr_link_rewrite" id="fr_link_rewrite" value="<?php echo $fr_category->link_rewrite ?>"></div>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Meta title tiếng Việt:</td>
            <td>
                <div style="width:400px;" dojoType=dijit.form.TextBox name="vi_meta_title" id="vi_meta_title" value="<?php echo $vi_category->meta_title ?>"></div>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Meta title tiếng Pháp:</td>
            <td>
                <input style="width:400px;" dojoType=dijit.form.TextBox name="fr_meta_title" id="fr_meta_title" value="<?php echo $fr_category->meta_title ?>"/>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Meta description tiếng Việt:</td>
            <td>
                <input style="width:400px;" dojoType=dijit.form.TextBox name="vi_meta_description" id="vi_meta_description" value="<?php echo $vi_category->meta_description ?>"/>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Meta description tiếng Pháp:</td>
            <td>
                <input style="width:400px;" dojoType=dijit.form.TextBox name="fr_meta_description" id="fr_meta_description" value="<?php echo $fr_category->meta_description ?>"/>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Meta keywords tiếng Việt:</td>
            <td>
                <input style="width:400px;" dojoType=dijit.form.TextBox name="vi_meta_keywords" id="vi_meta_keywords" value="<?php echo $vi_category->meta_keywords ?>""/>                                                        
            </td>
        </tr>
        <tr>
            <td width="150">Meta keywords tiếng Pháp:</td>
            <td>
                <input style="width:400px;" dojoType=dijit.form.TextBox name="fr_meta_keywords" id="fr_meta_keywords" value="<?php echo $fr_category->meta_keywords ?>"/>                                                        
            </td>
        </tr>
        <tr>
            <td><label></label></td>
            <td>                                    
                <button dojoType="dijit.form.Button" type="submit" id="submit" name="submit"
                        value="Add New">
                    Cập nhật
                </button>
            </td>				
        </tr>
    </table>
</div>